CMAKE_MINIMUM_REQUIRED(VERSION 2.6.3 FATAL_ERROR)
PROJECT(GCC C)

IF(GCCXML_INSTALL_COMPONENT_NAME_RUNTIME_EXECUTABLE)
  SET(GCCXML_INSTALL_COMPONENT_RUNTIME_EXECUTABLE
    COMPONENT ${GCCXML_INSTALL_COMPONENT_NAME_RUNTIME_EXECUTABLE})
ENDIF(GCCXML_INSTALL_COMPONENT_NAME_RUNTIME_EXECUTABLE)

# Do not place internal build-related executables in a parent project
# executable path.  Backup the real executable output path so it can
# be restored in gcc/cp for building gccxml_cc1plus.
SET(GCC_EXECUTABLE_OUTPUT_PATH ${EXECUTABLE_OUTPUT_PATH})
SET(EXECUTABLE_OUTPUT_PATH "${GCC_BINARY_DIR}/gcc")

# Do not inherit library building rules from the parent project.
SET(BUILD_SHARED_LIBS 0)
SET(LIBRARY_OUTPUT_PATH "${GCC_BINARY_DIR}/gcc")

SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_ANSI_CFLAGS}")

IF(APPLE AND CMAKE_C_COMPILER_ID MATCHES "^(GNU|Clang)$")
  SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -no-cpp-precomp")
ENDIF()

IF(CMAKE_C_COMPILER_ID MATCHES "^(Clang)$")
  SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c89")
  SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Qunused-arguments")
ENDIF()

# Suppress compiler warnings.
IF(MSVC)
  STRING(REGEX REPLACE "/W([0-4])?" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
  SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W0")
ELSEIF(BORLAND)
  SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w-")
ELSE()
  SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w")
ENDIF()

ADD_DEFINITIONS(-DALMOST_STDC)

SUBDIRS(config_cmake libiberty libdecnumber libcpp gcc)
